/**
 * Created with JetBrains WebStorm.
 * User: Chacha
 * Date: 12/06/13
 * Time: 13:40
 * To change this template use File | Settings | File Templates.
 */

var Recolter = function(){

    Action.call(this);

    this.name="Recolter";

    var self = this;
    this.sell = {
        name : "Vendre",
        do : function(plant,worldInterface)
        {
            console.log(plant);
            var price = plant.plantation.finalPrice * Math.floor(plant.real_maturity * plant.plantation.productivity / 100);
            plant.kill();
            worldInterface.dismiss();
            World.instance.getPersonage().money += price;
        },

        drawButton : function(ctx,worldInterface,actionButton){

            ctx.drawImage(
                self.sellImage,
                actionButton.x, actionButton.y, actionButton.width, actionButton.heigh);
            worldInterface.showFillText(ctx,this.name,
                actionButton.x + actionButton.width/2, actionButton.y - 10,"#7EDAEF","15pt Calibri","","center");
        }
    }

    this.harvestImage = new Image();
    this.harvestImage.src = "/images/recolter.jpg";

    this.sellImage = new Image();
    this.sellImage.src = "/images/sell.jpg";

}

Recolter.prototype = {

    canDo : function(plant,personage){

        if (this.distanceReq(plant,personage,300)){
            if(this.checkOwnership(plant.tile,personage)){
                if (this.checkMature(plant))
                    return true;
            }

        }
        return false;


    },

    do : function(plant,worldInterface){

        worldInterface.save();

        worldInterface.show(plant,[

            this.sell

        ],true);


    },

    drawButton : function(ctx,worldInterface,actionButton){

        ctx.drawImage(
            this.harvestImage,
            actionButton.x, actionButton.y, actionButton.width, actionButton.heigh);
        worldInterface.showFillText(ctx,this.name,
            actionButton.x + actionButton.width/2, actionButton.y - 10,"#7EDAEF","15pt Calibri","","center");
    }

}